package net.boss.fang.mq.producer;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQSender {

    @Autowired
    private ConnectionFactory rabbitConnectionFactory;
    
    @Value("${fang.exchange}")
    private String fangExchange;
    
    public void sendMessage(String exchange, Object msg) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(rabbitConnectionFactory);
        rabbitTemplate.setExchange(exchange);
        rabbitTemplate.setEncoding("UTF-8");
        rabbitTemplate.convertAndSend(msg);
    }
    
    public void sendFangInfo(Object message) {
        this.sendMessage(fangExchange, message);
    }
}
